/**
 * Created by Acery on 2016/12/5.
 */
$(function () {
    var dataList = null;
    var $self=$(this);
    $('#qry_btn').on('click tap', function (e) {
        var stu_name = $('#stuName').val();
        var stu_id = $('#stuId').val();
        if (stu_name == '' || stu_id == '') {
            $('#warn').html('学号和姓名不能为空!');
            setTimeout(function () {
                $('#warn').html('');
            }, 2000);
            return false
        }
        $self.attr('disabled', true);
        setTimeout(function () {
            $self.attr('disabled', false);
            $('#warn').html('');
        }, 2000);
        $.ajax({
            method: 'post',
            url: '',
            data: {
                'stu_name': stu_name,
                'stu_id': stu_id
            }
        })
            .done(function (data) {
                data = JSON.parse(data);
                if (data.result == 'ok') {
                    $('#warn').html('登录成功!');
                    dataList = data.list;
                    if(dataList.length==0){$('#warn').html('没有更多请假条！'); return false}
                    $('.aud-page').children().remove();
                    for (var i = 0; i < data.list.length; i++) {
                        $('#dataList').append('<li> <div class="page">' +
                            '<div class="page-left"></div>' +
                            '<div class="page-row page-time">' +
                            '<span>' + dataList[i].start_time + '</span>' +
                            '<span class="fenge">——></span> ' +
                            '<span>' + dataList[i].stop_time + '</span> ' +
                            '</div> ' +
                            '<div class="page-row page-reason">' +
                            '<span class="reason">理由：<span>' + dataList[i].reason + '</span></span> ' +
                            '<span class="where">地点：<span class="inwhere">' + dataList[i].location + '</span></span>' +
                            '<span class="sch">学院意见：<span>' + dataList[i].school_comment + '</span></span> <span class="daoy">导员意见：<span>' + dataList[i].director_comment + '</span></span> ' +
                            '</div>' +
                            '<div class="page-row page-btn"> ' +
                            '<span class="state">' + dataList[i].state + '</span> ' +
                            '</div> ' +
                            '</div> ' +
                            '</li>');
                        if(dataList[i].state==0){$('.aud-page li:eq('+i+')').find('.state').html('审核中');}
                        if(dataList[i].state==1){$('.aud-page li:eq('+i+')').find('.state').html('已同意');}
                        if(dataList[i].state==2){$('.aud-page li:eq('+i+')').find('.state').html('已驳回');}
                        $('#stuId').attr('disabled',true);
                        $('#stuName').attr('disabled',true);
                    }
                } else {
                    $('#warn').html('姓名或学号错误');
                }
            })
            .fail(function () {
                $('#warn').html('error:net');
            })

    })
});